package com.zdy.controller;

import com.zdy.entity.User;
import com.zdy.mapper.UserMapper;
import org.apache.ibatis.annotations.Delete;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;
import springfox.documentation.swagger2.annotations.EnableSwagger2;

import java.util.List;

/**
 * @Author: Deyou
 * @Date: 2021/4/14
 */
@EnableSwagger2
@RestController
public class UserController {
    @Autowired
    private UserMapper userMapper;

    /***
     * 查询所有用户信息
     * @return 返回所有用户
     */
    @GetMapping("/findAll")
    public List<User> findAll(){
        return userMapper.findAll();
    }

    /***
     * 根据Id 查询用户信息
     * @param id
     * @return
     */
    @GetMapping("/findById")
    public User findById(Integer id){
        return userMapper.findById(id);
    }

    /***
     * 添加用户
     * @param user
     * @return
     */
    @PostMapping("/insert")
    public String insert(@RequestBody User user){
        userMapper.insert(user);
        return "插入成功"+userMapper.findById(user.getUserId());
    }

    @PutMapping("/update")
    public String update(Integer id,String userName){
        userMapper.update(id,userName);
        return "插入成功"+userMapper.findById(id);
    }


    @DeleteMapping("/delete")
    public String delete(Integer id){
        userMapper.delete(id);
        return "删除数据用户id"+ id;
    }



}
